package cn.arikeky.service.impl;

import cn.arikeky.basic.util.PageList;
import cn.arikeky.domain.User;
import cn.arikeky.mapper.UserMapper;
import cn.arikeky.query.UserQuery;
import cn.arikeky.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findUserAll() {
        return userMapper.findUserAll();
    }

    @Override
    @Transactional
    public void add(User user) {
        userMapper.add(user);
    }

    @Override
    @Transactional
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        userMapper.delete(id);
    }

    @Override
    public User findById(Long id) {
        return userMapper.findById(id);
    }

    @Override
    public User findUser(User user) {
        User users = userMapper.findUser(user);
        if (null == users){
            throw new RuntimeException("登录失败");
        }
        return users;
    }

    @Override
    public PageList<User> queryByPage(UserQuery userQuery) {
        Integer totals = userMapper.queryByCount(userQuery);
        if (null == totals || 0 == totals){
            return new PageList<>();
        }
        List<User> users =userMapper.queryByPage(userQuery);
        return new PageList<>();
    }
}
